package com.xiaxiang.xiawan.Home.Adapter;

import android.content.Context;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.xiaxiang.xiawan.Home.HomeData;
import com.xiaxiang.xiawan.R;
import com.xiaxiang.xiawan.adapt.BaseRecyclerAdapter;
import com.xiaxiang.xiawan.adapt.BaseRecyclerViewHolder;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017-11-01.
 */

public class VideoAdapter extends BaseRecyclerAdapter<HomeData> {
    public List<HomeData> mHomeDataList;
    public VideoAdapter(Context context, List<HomeData> data) {
        super(context, data);
        mHomeDataList = data;
    }

    @Override
    public int getItemLayoutId(int viewType) {
        return R.layout.adp_item_showreel;
    }

    @Override
    public void bindData(BaseRecyclerViewHolder holder, int position, HomeData item) {

      ////  holder.mIcon = (ImageView)convertView.findViewById(R.id.imgVideoImg);
   //     holder.mUsername = (TextView)convertView.findViewById(R.id.tvVideoName);
     //   holder.mCheckBox = (CheckBox) convertView.findViewById(R.id.ckCheck);
        ImageView mIcon = (ImageView)holder.getImageView(R.id.imgVideoImg);
        TextView tvTitle =  (TextView)holder.getTextView(R.id.tvVideoName);
        CheckBox checkBox = (CheckBox) holder.getView(R.id.ckCheck);
        tvTitle.setText(item.mName);
        checkBox.setChecked(item.mIsSelect);
        if(item.mIsSelect){
            checkBox.setVisibility(View.VISIBLE);
        }else{
            checkBox.setVisibility(View.GONE);
        }
        final WeakReference<ImageView> imageViewWeakReference = new WeakReference<ImageView>(mIcon );
        ImageView weekImage = imageViewWeakReference.get();
        //  Glide.with(mContext).load(Uri.parse("file://" + data.mEffectThumbnailUrl)).into(weekImage);
        Glide.with(mContext).load(item.mThumbnailUrl).into(weekImage);
      //  weekImage.setBackgroundResource(R.drawable.app_icon);
    }

    public void addHomeDataByChange(HomeData data){
        mHomeDataList.add(data);
        notifyDataSetChanged();
    }

    public void addHomeData(HomeData data){
        mHomeDataList.add(data);
      //  notifyDataSetChanged();
    }

    public void clearData(){
        mHomeDataList.clear();
    }
}
